<html>
<head><meta charset="utf-8"><title>asm label and loop · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html">asm label and loop</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221480044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/221480044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gray Jack <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#221480044">(Jan 04 2021 at 00:43)</a>:</h4>
<p>Hi, all, I'm curious how to use labels in inline asm macro to create loops and I didn't found any examples in the unstable book. It's just like add a label in a str literal?</p>



<a name="221513504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/221513504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#221513504">(Jan 04 2021 at 11:31)</a>:</h4>
<p>It is the same way as for gcc inline asm.</p>



<a name="221553714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/221553714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gray Jack <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#221553714">(Jan 04 2021 at 17:28)</a>:</h4>
<p>Never needed gcc inline asm, but I guess it's easier to find information for gcc stuff</p>



<a name="221621856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/221621856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#221621856">(Jan 05 2021 at 08:16)</a>:</h4>
<p>You can write a label like <code>0:</code> or <code>1:</code>, then refer to it as <code>0b</code> or <code>1b</code>, meaning the first label found with that number going backwards.</p>



<a name="221621875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/221621875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#221621875">(Jan 05 2021 at 08:16)</a>:</h4>
<p><code>0f</code> works similarly but looks forward instead.</p>



<a name="221621901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/221621901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#221621901">(Jan 05 2021 at 08:17)</a>:</h4>
<p>You can define a loop by writing a label, then arranging to conditionally jump backwards to that label.</p>



<a name="221693478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/221693478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gray Jack <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#221693478">(Jan 05 2021 at 19:55)</a>:</h4>
<p>That worked on my test on ARM target! But sadly the inline asm didn't work out at all for a toy project I'm playing with, I thought it would work even though it's a custom target (thumbv5te-none-eabi) because it continues to be a ARM processor</p>



<a name="222179764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222179764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222179764">(Jan 09 2021 at 17:28)</a>:</h4>
<p>You may be able to add asm support for that target based on the existing ARM support.</p>



<a name="222179813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222179813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222179813">(Jan 09 2021 at 17:30)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> Any thoughts on handling Thumb targets for inline assembly? Any special handling needed there?</p>



<a name="222179973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222179973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222179973">(Jan 09 2021 at 17:32)</a>:</h4>
<p>Thumb restricts what instructions are allowed, but it's otherwise normal assembly as long as you stick to the correct subset.</p>



<a name="222180004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180004">(Jan 09 2021 at 17:33)</a>:</h4>
<p>nearly all of that would be handled by the assembler. the only part that rust would care about is the altered register availability. r0 to r7 are still general, r8 to 15 are severely limited in usage.</p>



<a name="222180051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180051">(Jan 09 2021 at 17:34)</a>:</h4>
<p>but even that I'm not sure if rust cares, because the assembler handles that too</p>



<a name="222180062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180062">(Jan 09 2021 at 17:34)</a>:</h4>
<p>you'll get an error if you use those registers incorrectly I think</p>



<a name="222180066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180066">(Jan 09 2021 at 17:35)</a>:</h4>
<p>yeah</p>



<a name="222180075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180075">(Jan 09 2021 at 17:35)</a>:</h4>
<p>hmm, I don't think <code>#[instruction_set]</code> handles this</p>



<a name="222180138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180138">(Jan 09 2021 at 17:36)</a>:</h4>
<p>uh, no, not as far as I'm aware. To an extent the goal was to make inline assembly not needed at all, so we kinda kicked that can down the road.</p>



<a name="222180189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180189">(Jan 09 2021 at 17:37)</a>:</h4>
<p>oh also: there's also more than one version of thumb the same as there's more than one version of arm, but again that's the assembler's job to handle. for rustc to do the <code>asm!</code> macro I don't think it matters.</p>



<a name="222180285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180285">(Jan 09 2021 at 17:39)</a>:</h4>
<p>(However I'll also note that I've always used external assembly files for all my assembly doings, even since the macro got the huge update and path to stabilization, since my needs map more to global_asm!, which the update didn't cover.)</p>



<a name="222180378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222180378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222180378">(Jan 09 2021 at 17:40)</a>:</h4>
<p><code>#[naked]</code> and <code>asm!</code> can be used to get what's basically global assembly</p>



<a name="222193181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/asm%20label%20and%20loop/near/222193181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/asm.20label.20and.20loop.html#222193181">(Jan 09 2021 at 22:37)</a>:</h4>
<p>when those are both stable I'll take a second look ;3</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>